<?php

namespace app\admin\model;

use think\Model;


class MemberGroup extends Model
{

    // 表名
    protected $name = 'member_group';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_win_text'
    ];
    
    public function getIsWinList()
    {
        return ['1' => __('Is_win 1'), '0' => __('Is_win 0')];
    }

    public function getIsWinTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_win']) ? $data['is_win'] : '');
        $list = $this->getIsWinList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function grouplog()
    {
        return $this->belongsTo('GroupLog', 'group_log_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
